<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>定时器</title>
</head>
<body>
    <h1>0</h1>
    <h2>0</h2>
    <script>
        let count=0;
        let timer = setInterval(fn,1000);
        function fn() {
            count++;
            let h1 = document.querySelector("h1");
            h1.innerText = count;
            if(count==5){
                clearInterval(timer);
            }
        }
        setInterval(function () {
            let h2 = document.querySelector("h2");
            h2.innerText=count;

        },2000);
    </script>
</body>
</html>